package com.weme.common.activity

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.widget.ImageView
import androidx.activity.OnBackPressedCallback
import com.bumptech.glide.Glide
import com.gyf.immersionbar.BarHide
import com.gyf.immersionbar.ImmersionBar
import com.weme.common.R
import com.weme.common.base.BaseActivity

class PhotoViewActivity : BaseActivity() {

    private var fullscreenImageView: ImageView? = null
    private val onBackPressedCallback = object : OnBackPressedCallback(true) {
        override fun handleOnBackPressed() {
            val intent = Intent()
            setResult(Activity.RESULT_OK, intent)
            finishAfterTransition()
        }
    }

    override fun initView(savedInstanceState: Bundle?) {
        setContentView(R.layout.activity_photo_view)
        ImmersionBar.with(this).hideBar(BarHide.FLAG_HIDE_NAVIGATION_BAR).init()
        fullscreenImageView = findViewById(R.id.fullscreenImageView)
        Glide.with(this).load(intent.getStringExtra("url")).into(fullscreenImageView!!)
        fullscreenImageView?.transitionName = "thumbnailTransition"
        postponeEnterTransition()
        startPostponedEnterTransition()
        fullscreenImageView?.setOnClickListener { onBackPressedCallback.handleOnBackPressed() }
    }

    override fun onResume() {
        super.onResume() // 添加回调，处理后退操作
        onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
    }

}
